package woogieunit;

import java.io.Serializable;

public class BenchmarkResult implements Serializable{
	/** Time (in nanoseconds) the bnehcmark took to execute */
	private long timeResult;
	/** Name of the benchmark (from the Benchmark annotation) */
	private String benchmarkName;
	/** Name of the suite this result was taken from (if applicable) */
	private String benchmarkSuite;
	/**Iteration of the benchmark this result was taken from (1 to n) */
	private int benchmarkIteration;
	/**Iteration of the benchmark suite this result was taken from, if applicable (0 to n)*/
	private int benchmarkSuiteIteration;
	
	/**
	 * Empty constructor
	 *
	 */
	public BenchmarkResult(){
		
	}

	/**
	 * @param timeResult
	 * @param benchmarkName
	 * @param benchmarkSuite
	 * @param benchmarkIteration
	 * @param benchmarkSuiteIteration
	 */
	public BenchmarkResult(long timeResult, String benchmarkName, String benchmarkSuite, int benchmarkIteration, int benchmarkSuiteIteration) {
		this.timeResult = timeResult;
		this.benchmarkName = benchmarkName;
		this.benchmarkSuite = benchmarkSuite;
		this.benchmarkIteration = benchmarkIteration;
		this.benchmarkSuiteIteration = benchmarkSuiteIteration;
	}

	/**
	 * @return the benchmarkIteration
	 */
	public int getBenchmarkIteration() {
		return benchmarkIteration;
	}

	/**
	 * @param benchmarkIteration the benchmarkIteration to set
	 */
	public void setBenchmarkIteration(int benchmarkIteration) {
		this.benchmarkIteration = benchmarkIteration;
	}

	/**
	 * @return the benchmarkName
	 */
	public String getBenchmarkName() {
		return benchmarkName;
	}

	/**
	 * @param benchmarkName the benchmarkName to set
	 */
	public void setBenchmarkName(String benchmarkName) {
		this.benchmarkName = benchmarkName;
	}

	/**
	 * @return the benchmarkSuite
	 */
	public String getBenchmarkSuite() {
		return benchmarkSuite;
	}

	/**
	 * @param benchmarkSuite the benchmarkSuite to set
	 */
	public void setBenchmarkSuite(String benchmarkSuite) {
		this.benchmarkSuite = benchmarkSuite;
	}

	/**
	 * @return the benchmarkSuiteIteration
	 */
	public int getBenchmarkSuiteIteration() {
		return benchmarkSuiteIteration;
	}

	/**
	 * @param benchmarkSuiteIteration the benchmarkSuiteIteration to set
	 */
	public void setBenchmarkSuiteIteration(int benchmarkSuiteIteration) {
		this.benchmarkSuiteIteration = benchmarkSuiteIteration;
	}

	/**
	 * @return the timeResult
	 */
	public long getTimeResult() {
		return timeResult;
	}

	/**
	 * @param timeResult the timeResult to set
	 */
	public void setTimeResult(long timeResult) {
		this.timeResult = timeResult;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
		final int PRIME = 31;
		int result = 1;
		result = PRIME * result + benchmarkIteration;
		result = PRIME * result + ((benchmarkName == null) ? 0 : benchmarkName.hashCode());
		result = PRIME * result + ((benchmarkSuite == null) ? 0 : benchmarkSuite.hashCode());
		result = PRIME * result + benchmarkSuiteIteration;
		result = PRIME * result + (int) (timeResult ^ (timeResult >>> 32));
		return result;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		final BenchmarkResult other = (BenchmarkResult) obj;
		if (benchmarkIteration != other.benchmarkIteration)
			return false;
		if (benchmarkName == null) {
			if (other.benchmarkName != null)
				return false;
		} else if (!benchmarkName.equals(other.benchmarkName))
			return false;
		if (benchmarkSuite == null) {
			if (other.benchmarkSuite != null)
				return false;
		} else if (!benchmarkSuite.equals(other.benchmarkSuite))
			return false;
		if (benchmarkSuiteIteration != other.benchmarkSuiteIteration)
			return false;
		if (timeResult != other.timeResult)
			return false;
		return true;
	}
	
	@Override
	public String toString(){
		if (benchmarkSuite != null){
			return "From suite " + benchmarkSuite + ", iteration " + benchmarkSuiteIteration  
			+ ": Benchmark " + benchmarkName + ", iteration " + benchmarkIteration + ". Result: " 
			+ timeResult + "ns.";
		}
		else {
			return "Benchmark " + benchmarkName + ", iteration " + benchmarkIteration + ". Result: " 
			+ timeResult + "ns.";
		}
	}
	
}
